// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueRouter from 'vue-router';
import routes from './routes'

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(VueRouter);

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  //router.options.routes[3].hidden=true;
  let authority = sessionStorage.getItem("authority");
  // console.log(authority)
  if(authority != null){
    router.options.routes.forEach((item)=>{
      if(authority.indexOf(item.name) > 0){
        item.hidden = false;
      }
    })
  }

  //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
    sessionStorage.removeItem('authority');
  }
  //console.log(sessionStorage.getItem("authority"))

  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  //el: '#app',
  router,
  //components: { App },
  //template: '<App/>'
  render: h => h(App)
}).$mount('#app')
